package com.example.test_01.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.test_01.R;
import com.example.test_01.model.User;
import com.example.test_01.service.UserService;
import com.example.test_01.service.UserServiceImpl;
import com.example.test_01.utils.Result;

import java.util.Date;

public class Regist extends BaseActivity implements View.OnClickListener {

    EditText InputUsername;
    EditText InputPassword;
    EditText InputNickName;

    Button BtnRegist;
    UserService userService = new UserServiceImpl();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        InputUsername = findViewById(R.id.input_username);
        InputPassword = findViewById(R.id.input_password);
        InputNickName = findViewById(R.id.input_nickname);
        BtnRegist = findViewById(R.id.btn_regist);
        BtnRegist.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_regist:
                String Username = InputUsername.getText().toString();
                String Password = InputPassword.getText().toString();
                String Nickname = InputNickName.getText().toString();
                User user = new User();
                user.setUsername(Username);
                user.setPassword(Password);
                user.setCreateTime(new Date());
                user.setNickname(Nickname);
                Result rec = userService.regist(user);
                if(rec == Result.SUCCESS){
                    // 注册成功
                    Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
                    finish();
                }
        }
    }
}